﻿#include "stdafx.h"
#include "Team_Raid_Info.h"
#include "boost/format.hpp"
#include <cmath> 

Team_Raid_Info::Team_Raid_Info()
{
}


Team_Raid_Info::~Team_Raid_Info()
{
}

Team_Raid_Info& GameInfo::GetTeam_Raid_Item(int nIndex)
{
	if (vec_team_and_raid_.size() > nIndex)
	{
		return *vec_team_and_raid_[nIndex];
	}
	throw std::exception("out of index");
}

void Team_Raid_Info::aura_buffs_to_map()
{
	// vector to map
	map_buff_.clear();
	for (int i = 0; i < buffs.size(); i++) {
		auto & buff = buffs[i];
		map_buff_[buff.spell_id] = buff;
	}
	// vector to map
	map_debuff_.clear();
	for (int i = 0; i < debuffs.size(); i++) {
		auto & debuff = debuffs[i];
		map_debuff_[debuff.spell_id] = debuff;
	}
}

int Team_Raid_Info::GetExpectHealValue()
{
	int nHealTotal = 0;
	for (int i = 0; i < buffs.size(); i++)
	{
		nHealTotal += GetHealExceptHpTotal((SpellID)buffs[i].spell_id, buffs[i].duration);
	}
	return nHealTotal;
}

std::string Team_Raid_Info::GetName()
{
	return target_name;
}

void Team_Raid_Info::MakeTargetName()
{
	if (isRaidOrParty == 2)
	{
		target_name = boost::str(boost::format("party%d") % index);
	}
	else if (isRaidOrParty == 3) {
		target_name = boost::str(boost::format("raid%d") % index);
	}
}

BuffOrDebuff Team_Raid_Info::buff(SpellID id)
{
	BuffOrDebuff copy;
	auto it = map_buff_.find(id);
	if (it != map_buff_.end())
	{
		copy = it->second;
	}
	return std::move(copy);
}

BuffOrDebuff Team_Raid_Info::debuff(SpellID id)
{
	BuffOrDebuff copy;
	auto it = map_debuff_.find(id);
	if (it != map_debuff_.end())
	{
		copy = it->second;
	}
	return std::move(copy);
}

double Team_Raid_Info::LostHpPecent()
{
	return (player_hp_max - player_hp) * 1.0f / player_hp_max;
}

double Team_Raid_Info::HpPecent()
{
	return player_hp * 1.0f / player_hp_max;
}

bool Team_Raid_Info::IsDeadOrGhost()
{
	return is_dead_or_ghost == 1;
}

GroupRoleType Team_Raid_Info::GetUnitRole()
{
	return (GroupRoleType)unit_role;
}

double Team_Raid_Info::GetDistance()
{
	int p_y1 = GameInfo::inst().GetPlayer().y1;
	int p_x1 = GameInfo::inst().GetPlayer().x1;

	double dis = sqrt(pow((p_y1 - y1), 2) + pow((p_x1 - x1), 2));
	return dis / 10.0f;
}
